const { override, fixBabelImports, adjustStyleLoaders, addWebpackPlugin  } = require('customize-cra');

const path = require('path');

const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

function overrideWebpack(config) {
    config.resolve.alias = {
        ...config.resolve.alias,
        '@': path.resolve(__dirname, 'src'),
    };

    return config;
}

module.exports = {
    webpack: override(
        fixBabelImports('antd', {
            libraryDirectory: 'es',
            style: 'css',
        }),
        adjustStyleLoaders((rule) => {
            if (rule.test.toString().includes('scss')) {
                rule.use.push({
                    loader: require.resolve('sass-resources-loader'),
                    options: {
                        resources: './src/assets/scss/base.scss',
                    },
                });
            }
        }),
        overrideWebpack,
        process.env.NODE_ENV === 'production' && addWebpackPlugin(new UglifyJsPlugin({
            uglifyOptions: {
              compress: {
                drop_debugger: true,
                drop_console: true
              }
            }
        }))
    ),
};
